package com.wl156.activities.order;

import java.io.IOException;

import org.xmlpull.v1.XmlPullParserException;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import com.wl156.R;
import com.wl156.activities.find.FindResultBase;
import com.wl156.adapters.GoodAdapter;

public class GetMyGoodResult extends FindResultBase {

	String endLocationLv1;
	String endLocationLv2;
	String endLocationLv3;
	String goodName;
	String truckTonnage;
	String truckTonnageSymBol;
	String truckLength;
	String truckLengthSymbol;
	String setOffDate;
	String setOffDateSymbol;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		mHeaderStub.setLayoutResource(R.layout.item_good_header);
		mHeaderStub.inflate();

		Bundle extras = getIntent().getExtras();
		startLocationLv1 = extras.getString("startLocationLv1");
		startLocationLv2 = extras.getString("startLocationLv2");
		startLocationLv3 = extras.getString("startLocationLv3");
		endLocationLv1 = extras.getString("endLocationLv1");
		endLocationLv2 = extras.getString("endLocationLv2");
		endLocationLv3 = extras.getString("endLocationLv3");
		goodName = extras.getString("goodName");
		truckTonnage = extras.getString("truckTonnage");
		truckTonnageSymBol = extras.getString("truckTonnageSymBol");
		truckLength = extras.getString("truckLength");
		truckLengthSymbol = extras.getString("truckLengthSymbol");
		setOffDate = extras.getString("setOffDate");
		setOffDateSymbol = extras.getString("setOffDateSymbol");

		hideBottomButtons();
		
		new FindTask(type).execute();
		
		setTitle("我的货讯");
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);

		Intent i = new Intent(GetMyGoodResult.this, MyGoodInfo.class);
		i.putExtra("id", id);
		startActivity(i);
	}

	@Override
	protected int getPhoneIndex() {
		return 8;
	}

	@Override
	protected String getFindName() {
		return "我的货讯";
	}

	@Override
	protected Class getFindActivity() {
		return GetMyGood.class;
	}

	@Override
	protected Class getFindResultActivity() {
		return GetMyGoodResult.class;
	}

	@Override
	protected void onLastItemVisible() {
		super.onLastItemVisible();

		new FindTask(type).execute();
	}

	public class FindTask extends FindTaskBase {
		public FindTask(int type) {
			super(type);
		}

		@Override
		protected void onLoadFailed() {
			super.onLoadFailed();

			new FindTask(type).execute();
		}

		@Override
		protected Object doInBackground(Void... params) {
			try {
				return mWebServiceClient.companyFindMyFreightMessage(
						mCertificate, startLocationLv1, startLocationLv2,
						startLocationLv3, endLocationLv1, endLocationLv2,
						endLocationLv3, goodName, truckTonnage,
						truckTonnageSymBol, truckLength, truckLengthSymbol,
						setOffDate, setOffDateSymbol, mCurrentPageIndex,
						countPerPage, null);
			} catch (IOException e) {
				return e;
			} catch (XmlPullParserException e) {
				return e;
			}
		}
	}

	@Override
	protected Class getAdapter() {
		return GoodAdapter.class;
	}

}
